package com.weimob.mcloud.wechatwork.customer.facade.impl.customer;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.weimob.mcloud.wechatwork.core.base.MultiResponse;
import com.weimob.mcloud.wechatwork.core.base.SingleRequest;
import com.weimob.mcloud.wechatwork.core.entity.privatesphere.PrivateSphere;
import com.weimob.mcloud.wechatwork.core.entity.relation.CustomerEmployeeRelation;
import com.weimob.mcloud.wechatwork.core.entity.relation.customer.Customer;
import com.weimob.mcloud.wechatwork.core.service.customer.CustomerService;
import com.weimob.mcloud.wechatwork.core.service.privatesphere.PrivateSphereService;
import com.weimob.mcloud.wechatwork.customer.facade.impl.BaseTest;
import com.weimob.mcloud.wechatwork.customer.job.CustomerJob;
import com.weimob.mcloud.wechatwork.customer.service.user.base.BasicInfo;
import com.weimob.mcloud.wechatwork.customer.service.user.base.PageResponse;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.customer.*;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.*;
import com.weimob.mcloud.wechatwork.customer.service.user.service.CustomerExport;
import com.weimob.soa.common.response.SoaResponse;
import com.weimob.soa.common.utils.SoaUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class CustomerFacadeTestly extends BaseTest {

    @Reference
    private CustomerExport customerExport;

    @Reference
    private CustomerService customerService;
    @Reference
    private PrivateSphereService privateSphereService;
    @Autowired
    private CustomerJob customerJob;
    @Test
    public void testFindActionLog(){
        CorpActionLogFindDTO corpActionLogFindDTO = new CorpActionLogFindDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(4000164807753L);
        corpActionLogFindDTO.setBasicInfo(basicInfo);
        corpActionLogFindDTO.setBizType(1);
        corpActionLogFindDTO.setPageNum(1);
        corpActionLogFindDTO.setPageSize(20);
        PageResponse<CustomerActionLogBO> unpack = SoaUtil.unpack(customerExport.findCorpActionLog(corpActionLogFindDTO));
        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void testAddActionLog(){
        CorpActionLogInsertDTO corpActionLogInsertDTO = new CorpActionLogInsertDTO();
        BasicInfo basicInfo = new BasicInfo();

        basicInfo.setBosId(4000136704212L);
        basicInfo.setMerchantId(2000000016212L);
        basicInfo.setProductId(203L);
        basicInfo.setProductInstanceId(6597212L);
        basicInfo.setProductVersionId(12054L);
        corpActionLogInsertDTO.setBasicInfo(basicInfo);
        corpActionLogInsertDTO.setCustomerId("asda");
        corpActionLogInsertDTO.setOrgUserId("bbb");
        CustomerActionLogBO unpack = SoaUtil.unpack(customerExport.addActionLog(corpActionLogInsertDTO));

        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void testAddress(){
        DivisionFindDTO corpActionLogInsertDTO = new DivisionFindDTO();
        corpActionLogInsertDTO.setParentCode("1");
        corpActionLogInsertDTO.setDegree(1);
        List<DivisionBO> unpack = SoaUtil.unpack(customerExport.findDivisionList(corpActionLogInsertDTO));

        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void getExternalUserByWids(){
        ExternalUserInfoFindDTO corpActionLogInsertDTO = new ExternalUserInfoFindDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(4000136704212L);
        corpActionLogInsertDTO.setBasicInfo(basicInfo);
        corpActionLogInsertDTO.setWidList(Lists.newArrayList(100533815L));
        final PageResponse<ExternalUserListBO> unpack = SoaUtil.unpack(customerExport.getExternalUserByWids(corpActionLogInsertDTO));

        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void getCustomerBaseInfo(){
        CustomerIdGetDTO customerIdGetDTO = new CustomerIdGetDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(4000136704212L);
        customerIdGetDTO.setBasicInfo(basicInfo);

        customerIdGetDTO.setCustomerId("20211105003010003100000000040003");
//        customerIdGetDTO.setExternalUserId("wmxQg3CgAAgDTh6CAvPebbNVRBAcfwjw");
        CustomerDetailBO unpack = SoaUtil.unpack(customerExport.getCustomerBaseInfo(customerIdGetDTO));

        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void getExternalUserRelationByWids(){
        ExternalUserInfoByWidsDTO corpActionLogInsertDTO = new ExternalUserInfoByWidsDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(4000165815829L);
        basicInfo.setProductInstanceId(11870829L);
        basicInfo.setVid(0L);
        corpActionLogInsertDTO.setBasicInfo(basicInfo);
        corpActionLogInsertDTO.setWids(Lists.newArrayList(100537434L));
        List<ExternalUserRelationBO> unpack = SoaUtil.unpack(customerExport.getExternalUserRelationByWids(corpActionLogInsertDTO));

        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void testCreateCustomer() {
        Customer customer = new Customer();
        customer.setExternalUserid("qwerqwerqwer");
        customer.setCorpId("8888");
        Customer unpack = SoaUtil.unpack(customerService.createCustomer(customer));
        System.out.println(JSON.toJSONString(unpack));
    }
    @Test
    public void getByids() {
        PrivateSphere privateSphere = new PrivateSphere();
        privateSphere.setCorpId("ww19821d6bba93b974");
//        privateSphere.setSuiteId("wwd4c2f0ff1359caa2");
        PrivateSphere aaa = SoaUtil.unpack(privateSphereService.searchOne(privateSphere));
        List<PrivateSphere> privateSphereResult = SoaUtil.unpack(privateSphereService.search(privateSphere));
//        privateSphere = privateSphereResult.stream().filter(item -> platformSuiteIds.contains(item.getSuiteId())).findFirst().orElse(privateSphere);
        CustomerIdGetDTO customer = new CustomerIdGetDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(privateSphere.getBosId());
        customer.setBasicInfo(basicInfo);
        customer.setExternalUserId("wmxQg3CgAAc3H2T8chwhnRIS7iZAEOZw");
        CustomerDetailBO unpack = SoaUtil.unpack(customerExport.getCustomerBaseInfo(customer));
        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void testFetchCustomerRel() {
        CustomerEmployeeRelation customerEmployeeRelation = new CustomerEmployeeRelation();
        SingleRequest<CustomerEmployeeRelation> customer = new SingleRequest<>(customerEmployeeRelation);
        customerEmployeeRelation.setCustomerId("20211107003010005700000000064002");
        MultiResponse<CustomerEmployeeRelation> unpack = SoaUtil.unpack(customerService.fetchCustomerEmployeeRelation(customer));
        System.out.println(JSON.toJSONString(unpack));
    }

    @Test
    public void testupdateRemark() {
//        CustomerRemarkDTO customerRemarkDTO = new CustomerRemarkDTO();
//        BasicInfo basicInfo = new BasicInfo();
//        basicInfo.setBosId(4000166041271L);
//        basicInfo.setProductInstanceId(12063271L);
//        basicInfo.setProductId(203L);
//        customerRemarkDTO.setBasicInfo(basicInfo);
//        customerRemarkDTO.setCustomerId("20211117003010000300000000230001");
//        customerRemarkDTO.setEmployeeId("20211109004010000300000000050086");
//        customerRemarkDTO.setRemark("SHY（测试）");
//
//        SoaResponse<Boolean, ?> booleanSoaResponse = customerExport.updateCustomerRemark(customerRemarkDTO);
//        System.out.println(JSON.toJSONString(booleanSoaResponse));

//        CustomerByEmployeeDTO customerByEmployeeDTO = new CustomerByEmployeeDTO();
//        customerByEmployeeDTO.setTxUserId("bigpillar");
//        customerByEmployeeDTO.setEmployeeId("20211108004010000800000000024080");
//        BasicInfo basicInfo = new BasicInfo();
//        basicInfo.setCorpId("ww3b5a4010aa0f8312");
//        customerByEmployeeDTO.setBasicInfo(basicInfo);
//        customerByEmployeeDTO.setPageNum(1);
//        customerByEmployeeDTO.setPageSize(20);
//        SoaResponse<PageResponse<CustomerDetailBO>, ?> customerListByEmployee = customerExport.getCustomerListByEmployee(customerByEmployeeDTO);
//        System.out.println(JSON.toJSONString(customerListByEmployee));

//        Customer customer = new Customer();
//        SingleRequest<Customer> request = new SingleRequest<>(customer);
//        SoaResponse<MultiResponse<Customer>, ?> multiResponseSoaResponse = customerService.fetchCustomer(request);
//        System.out.println(JSON.toJSONString(multiResponseSoaResponse));

        ExternalUserInfoFindDTO externalUserInfoFindDTO = new ExternalUserInfoFindDTO();
        BasicInfo basicInfo = new BasicInfo();
        basicInfo.setBosId(4000167857028L);
        externalUserInfoFindDTO.setBasicInfo(basicInfo);
        externalUserInfoFindDTO.setWidList(Lists.newArrayList(100542046L));
        SoaResponse<PageResponse<ExternalUserListBO>, ?> externalUserByWids = customerExport.getExternalUserByWids(externalUserInfoFindDTO);
        System.out.println(JSON.toJSONString(externalUserByWids));
    }
}